# -*- coding: utf-8 -*-
from seekfree import ENCODER
from seekfree import TIMER
from seekfree import GPIO

def tim1_callback(s):
    global n
    global flag
    n = encoder1.value()
    encoder1.reset()
    flag = 1

ENCODER.help()                                  # 模块使用说明

encoder1 = ENCODER(1, 1)                        # 初始化 ENCODER1 接口 为正交解码器模式
# encoder1.enable()
# encoder1.disable()
tim1 = TIMER(500)                               # 500ms 定时器
tim1.callback(tim1_callback)                    # 设置回调

pinpg3 = GPIO(0x63, 0, 1)                       # G3 输入 上拉

n = 0
flag = 0
while 1:
    if flag:
        print(n)
        flag = 0

    if pinpg3.value() == 0:                     # 按下按键 G3
        print("Exti ENCODER test program.\n")
        break                                   # 退出测试程序 （如果接下来要运行其他代码请先退出本测试程序）
